<?

/**
* Global javascript helper functions
*
* @author Adesanto Asman
* @version 1.0
* @license Free
* @package CGJavascript
*
*/

class CGJavascript{

  /**
  * onFocus()
  *
  * @param  string    $colFunctions   Collections of function
  * @return string
  *
  */
  function jsOnFocus($colFunctions){

    return " onFocus='".$colFunctions."' ";
  }

  /**
  * onBlur()
  *
  * @param  string    $colFunctions   Collections of function
  * @return string
  *
  */
  function jsOnBlur($colFunctions){

    return " onBlur='".$colFunctions."' ";
  }

  /**
  * onChange()
  *
  * @param  string    $colFunctions   Collections of function
  * @return string
  *
  */
  function jsOnChange($colFunctions){

    return " onChange='".$colFunctions."' ";
  }

  /**
  * onClick()
  *
  * @param  string    $colFunctions   Collections of function
  * @return string
  *
  */
  function jsOnClick($colFunctions){

    return " onClick='".$colFunctions."' ";
  }

  /**
  * onMouseOver()
  *
  * @param  string    $colFunctions   Collections of function
  * @return string
  *
  */
  function jsOnMouseOver($colFunctions){

    return " onMouseOver='".$colFunctions."' ";
  }

  /**
  * onMouseOut()
  *
  * @param  string    $colFunctions   Collections of function
  * @return string
  *
  */
  function jsOnMouseOut($colFunctions){

    return " onMouseOut='".$colFunctions."' ";
  }

  /**
  * Manual script or as javascript default tag
  *
  */
  function jsScript($source, $script){

    if($source){

      return  " <script language='javascript'   src='".$source."' ></script> \n".
              " <script language='javascript' > ".$script."  </script>\n";
    }else{

      return " <script language='javascript' > ".$script." </script> ";
    }
  }

  /**
   * js includer
   *
   * @param string  $type
   * @param string  $source
   */
  function includeThis($type, $source){

    switch($type){

      case _TYPE_CSS:

        return  " <link rel=\"stylesheet\" type=\"text/css\" href=\"".$source."\">\n";
      case _TYPE_JS:

        return  " <script language='javascript'   src='".$source."' ></script> \n";
      default:

        return NULL;
    }
  }

  /**
  * onKeyDown()
  *
  * @param  string    $colFunctions   Collections of function
  * @return string
  *
  */
  function jsOnKeyDown($colFunctions){

    return " onKeyDown='".$colFunctions."' ";
  }

  /**
   * stop/disble the enter key
   *
   */
  function stopRKey(){

    return "<script type=\"text/javascript\">

            function stopRKey(evt) {
              var evt = (evt) ? evt : ((event) ? event : null);
              var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
              if ((evt.keyCode == 13) && (node.type==\"text\"))  {return false;}
            }

            document.onkeypress = stopRKey;

            </script> ";
  }
}

?>